package ReadingData;

import java.io.*;
import java.util.Properties;
import java.util.logging.Logger;

import util.MyLogging;
import UserException.VariableException;

public class ReadData {

	private final static Logger LOGGER = new MyLogging()
			.getLogger(ReadData.class.getName());

	public static String readData(String lname, String fname) {
		String lvalue = "";

		if (lname.length() == 0)
			return lvalue;

		Properties prop = new Properties();
		InputStream input = null;

		try {

			input = new FileInputStream(fname);

			// load a properties file
			prop.load(input);

			if (prop.containsKey(lname))
				lvalue = prop.getProperty(lname);
			else
				new VariableException(lname);

			LOGGER.info(lname + " " + lvalue);

		} catch (FileNotFoundException e) {

			LOGGER.severe("File Not found " + fname);
		} catch (IOException e) {
			LOGGER.severe("Cant read from file " + lname + " from file "
					+ fname);
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException e) {
					LOGGER.severe("File not found " + fname);

				}
			}
		}

		return lvalue;

	}

	/*
	 * public static void main(String[] args) { // String result = readData("",
	 * "c:\\springsource\\jdbc.properties"); }
	 */

}
